package com.jinxin.platform.cddjnhjcxtsysset.controller;

import com.jinxin.platform.base.api.annotation.APCOSApi;
import com.jinxin.platform.base.api.annotation.APCOSApiOperation;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cddjnhjcxtsysset.bean.CddjnhjcxtsyssetHomeRange;
import com.jinxin.platform.cddjnhjcxtsysset.common.Constant;
import com.jinxin.platform.cddjnhjcxtsysset.common.SysUserVO;
import com.jinxin.platform.cddjnhjcxtsysset.rpc.CddjnhjcxtsyssetRpc;
import com.jinxin.platform.cddjnhjcxtsysset.service.ICddjnhjcxtsyssetHomeRangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @Author 那个男人
 * @Date 2022/5/11 10:48
 * @Version 1.0
 */
@APCOSApi(value = "首页工作区间相关接口", developers = {"lingnan"}, description = "首页工作区间相关接口")
@Api(tags = "首页工作区间相关接口")
@RestController
@RequestMapping("/cddjnhjcxtsysset/cddjnhjcxtsyssetHomeRange")
@Slf4j
public class CddjnhjcxtsyssetHomeRangeController {
    @Autowired
    private ICddjnhjcxtsyssetHomeRangeService homeRangeService;
    @Autowired
    private CddjnhjcxtsyssetRpc cddjnhjcxtsyssetRpc;

    @APCOSApiOperation(value = "查询当前组织下的工作区间", developers = {"lingnan"}, description = "查询当前组织下的工作区间",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_WEB)
    @ApiOperation(value = "查询当前组织下的工作区间")
    @ApiImplicitParams({})
    @GetMapping("/get")
    public JsonResult get(){
        SysUserVO currentUser = cddjnhjcxtsyssetRpc.getCurrentUser();
        if(currentUser == null){
            return JsonResult.error("获取当前用户信息失败");
        }
        HashMap param = new HashMap();
//        param.put("type", type);
        if(Constant.ACCOUNT_ADMIN.equals(currentUser.getUserAccount())){
            param.put("orgId", Constant.STRING_ZERO);
        }else {
            param.put("orgId", currentUser.getOrgId());
        }
        CddjnhjcxtsyssetHomeRange homeRange = homeRangeService.selectOne(param);
        return JsonResult.ok("success",homeRange);
    }

    @PostMapping("/saveOrUpdate")
    public JsonResult saveOrUpdate(@RequestBody CddjnhjcxtsyssetHomeRange record){
        return homeRangeService.saveOrUpdate(record);
    }
}
